package com.xuanwoa.rabbit.delay.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * Description
 *
 * @author: xuanwoa
 * @since: 2020/11/15
 */
@Configuration
public class DelayQueueConfig {

    @Bean
    public Queue delayQueue() {
        return new Queue("delayqueue");
    }

    @Bean
    public DirectExchange delayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        DirectExchange exchange = new DirectExchange("delay.exchange", true, false, args);
        exchange.setDelayed(true);
        return exchange;
    }

    @Bean
    public Binding delayBinding() {
        return BindingBuilder
                .bind(delayQueue())
                .to(delayExchange())
                .with("delayqueue");
    }
}
